package com.banmao.algorithm.No701To900.No707;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;

@Aspect
public class AspectConfig {

    //@Pointcut("execution(* com.banmao.algorithm.No707.MyLinkedList.*(..))")
    @Pointcut("execution(* com.banmao.algorithm.No701To900.No707.MyLinkedList.*(..)) && !execution(* com.banmao.algorithm.No701To900.No707.MyLinkedList.printLinkedList())")
    private void pointcut() {}

    @After("pointcut()")
    public void after(JoinPoint joinPoint) {
        MyLinkedList target = (MyLinkedList) joinPoint.getTarget();
        target.printLinkedList();
        // 输出真实长度和保存的长度
        int size = target.size;

        LinkedNode cur = target.dummy_head.next;
        int realSize = 0;
        while (cur != null) {
            realSize++;
            cur = cur.next;
        }

        if(realSize != size) {
            throw new RuntimeException("长度有误, realSize: " + realSize + ", size: " + size);
        }

        System.out.printf("realSize: %d, size: %d \n", realSize, size);

    }

}
